#include <stdio.h>
const int N = 500 + 5;
int n, m;
int a[N][N], b[N][N];
void change(int x, int y)
{
a[x][y] = a[x][y] == 1 ? 0 : 1;
a[x + 1][y] = a[x + 1][y] == 1 ? 0 : 1;
a[x][y + 1] = a[x][y + 1] == 1 ? 0 : 1;
a[x + 1][y + 1] = a[x + 1][y + 1] == 1 ? 0 : 1;
}
int main()
{
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
scanf("%d", &a[i][j]);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
scanf("%d", &b[i][j]);
for (int i = 1; i < n; i++)
for (int j = 1; j < m; j++)
if (a[i][j] != b[i][j])
change(i, j);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (a[i][j] != b[i][j])
{
puts("No");
return 0;
}
puts("Yes");
return 0;
}
1440A - Buy the String | 1658F - Juju and Binary String |
478A - Initial Bet | 981A - Antipalindrome |
365A - Good Number | 1204B - Mislove Has Lost an Array |
1409D - Decrease the Sum of Digits | 1476E - Pattern Matching |
1107A - Digits Sequence Dividing | 1348A - Phoenix and Balance |
1343B - Balanced Array | 1186A - Vus the Cossack and a Contest |
1494A - ABC String | 1606A - AB Balance |
1658C - Shinju and the Lost Permutation | 1547C - Pair Programming |
550A - Two Substrings | 797B - Odd sum |
1093A - Dice Rolling | 1360B - Honest Coach |
1399C - Boats Competition | 1609C - Complex Market Analysis |
1657E - Star MST | 1143B - Nirvana |
1285A - Mezo Playing Zoma | 919B - Perfect Number |
894A - QAQ | 1551A - Polycarp and Coins |
313A - Ilya and Bank Account | 1469A - Regular Bracket Sequence |